package org.example.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.sql.ResultSet;
import java.sql.SQLException;

public class Order {
    private int orderId;
    private int userId;
    private double totalAmount;
    private int orderStatus;
    private String createTime;
    private String payTime;

    public Order(){}

    public Order(int userId,double totalAmount,int orderStatus,String createTime,String payTime){
        this.userId=userId;
        this.totalAmount=totalAmount;
        this.orderStatus=orderStatus;
        this.createTime=createTime;
        this.payTime=payTime;
    }

    public int getOrderId() {
        return orderId;
    }

    public int getUserId() {
        return userId;
    }

    public double getTotalAmount() {
        return totalAmount;
    }

    public String getOrderStatus() {
        if(orderStatus==1){
            return "未支付";
        }else{
            return "已支付";
        }
    }

    public String getCreateTime() {
        return createTime;
    }

    public String getPayTime() {
        return payTime;
    }



    public void setOrderId(int orderId) {
        this.orderId = orderId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public void setTotalAmount(double totalAmount) {
        this.totalAmount = totalAmount;
    }

    public void setOrderStatus(int orderStatus) {
        this.orderStatus = orderStatus;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public void setPayTime(String payTime) {
        this.payTime = payTime;
    }

    @Override
    public String toString() {
        return "Order{"+
                "orderId="+orderId+
                ",userId="+userId+
                ",totalAmount="+totalAmount+
                ",orderStatus="+orderStatus+
                ",createTime='"+createTime+'\''+
                ",payTime='"+payTime+'\''+
                '}';
    }

    public static Order map(ResultSet rs) throws SQLException {
        Order order=new Order();
        int orderId=rs.getInt("ord_id");
        int userId= rs.getInt("user_id");
        double totalAmount=rs.getDouble("total_amount");
        int orderStatus=rs.getInt("ord_status");
        String createTime=rs.getString("create_time");
        String payTime=rs.getString("pay_time");
        order.setOrderId(orderId);
        order.setUserId(userId);
        order.setTotalAmount(totalAmount);
        order.setOrderStatus(orderStatus);
        order.setCreateTime(createTime);
        order.setPayTime(payTime);
        return order;
    }
}